<?php
include_once("../../service/productService.php");
include_once("../../service/categoryService.php");

$proId = $_POST["proId"];

$productInfo = findProductBy($proId);
$categories = getAllParentCategoriesOf($productInfo["CAT_ID"], null);
$categories[] = array("id" => $productInfo["CAT_ID"]);

echo '<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>Sản phẩm</div><div class="modal-body">';

echo "<table border='0'>";
echo "<tr><td>Giảm giá</td><td>".$productInfo["DISCOUNT"]."</td></tr>";
echo "<tr><td>Nhóm sản phẩm</td><td>".$productInfo["CATEGORY"]."</td></tr>";
echo "<tr><td>Mã</td><td>".$productInfo["PRO_CODE"]."</td></tr>";
echo "<tr><td>Tên</td><td>".$productInfo["PRO_NAME"]."</td></tr>";
echo "<tr><td>Trạng thái</td><td>".$productInfo["STATUS"]."</td></tr>";
echo "<tr><td>Giá</td><td>".number_format($productInfo["PRO_PRICE"])."</td></tr>";
echo "<tr><td>Mô tả</td><td>".$productInfo["PRO_DESCRIPTION"]."</td></tr>";
echo "<tr><td><table border='0'>";
echo "<tr><td>Thuộc tính</td></tr>";

foreach($categories as $each){
    $attributes = getAttributesOfCategory($each["id"]); 
    while($row = ConnectionManager::getInstance()->fetch($attributes)){
        echo "<tr><td>".$row["ATT_NAME"]."</td></tr>";   
    }
}
        
echo "</table></td>";
echo "<td><table border='0'>";
echo "<tr><td>Lựa chọn phụ</td></tr>";

foreach($categories as $each){
    $optionalPrices = getOptionalPricesOfCategory($each["id"]);
    while($row = ConnectionManager::getInstance()->fetch($optionalPrices)){
        echo "<tr><td>".$row["OPP_NAME"]."</td></tr>";   
    }
}

echo "</td></tr>";
echo "</table>";
echo '</div><div class="modal-footer"></div>';
/**
 * 
<div class="modal-header">
	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    Sản phẩm
</div>
<div class="modal-body">
	Thuoc tinh:
</div>
<div class="modal-footer"></div>
*/
?>